package com.pinapel.aixml.ui;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;

import com.pinapel.aixml.tools.i18n.I18n;


public class MainWindow extends JFrame{
	private JMenuBar jMenuBar;
	private JTabbedPane jTree;
//	private JComponent jLogUI;
	private JTabbedPane jTabbedLog;
	private JTabbedPane jEditors;
	private JPanel jButtons;
	
	//private IMainController controller;
	/**
	 * 
	 */
	private static final long serialVersionUID = 201204121627L;
	

    /**
     * Creates new form InterfazPrincipal
     */
    public MainWindow() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    private void initComponents() {

        jTree = new ArbolesUI();
        jEditors = new EditorsUI();
        jMenuBar = new MenuUI();
//        jLogUI = new LogUI();
        jTabbedLog = new TabbedLogUI();
        jButtons = new ButtonsUI(); 

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle(I18n.getString(I18n.UI000_TITLE));

        // Create a instance of main controller
//        controller = DaddySmurfController.getInstance();
//        controller.setView(this);
        
        // Set the menuBar
        this.setJMenuBar(jMenuBar);
        
        //Create the layout and assign it to view 
        BorderLayout mainLayout = new BorderLayout();
        this.setLayout(mainLayout);
       
        // Create the editors and log vies in a dynamic jSplitPane
        JSplitPane componentForEditorsAndLog = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
        componentForEditorsAndLog.add(jEditors, JSplitPane.TOP);
//        componentForEditorsAndLog.add(jLogUI, JSplitPane.BOTTOM);
        componentForEditorsAndLog.add(jTabbedLog, JSplitPane.BOTTOM);
        
        // Create the JSplitPane to divide the screen
        JSplitPane jspane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
        jspane.add(jTree, JSplitPane.LEFT);
        jspane.add(componentForEditorsAndLog, JSplitPane.RIGHT);
        
        this.add(jspane, BorderLayout.CENTER);
        this.add(jButtons, BorderLayout.NORTH);
        
        
        // Dimensions Provisional
//        jLogUI.setPreferredSize(new Dimension(480,60));
        jTabbedLog.setPreferredSize(new Dimension(480,60));
        jEditors.setPreferredSize(new Dimension(480,270));
        jTree.setPreferredSize(new Dimension(132,320));
        componentForEditorsAndLog.setDividerLocation(0.82);
        jspane.setDividerLocation(0.15);
        
        pack();
    }
    
    public MenuUI getMenuBarUI() {
		return (MenuUI) jMenuBar;
	}

	public ArbolesUI getTreeUI() {
		return (ArbolesUI) jTree;
	}

	public TabbedLogUI getTabbedLogUI() {
		return (TabbedLogUI) jTabbedLog;
	}
	
	public LogUI getLogUI() {
		return ((TabbedLogUI) jTabbedLog).getLogUI();
	}

	public EditorsUI getEditorsUI() {
		return (EditorsUI) jEditors;
	}
	
	public ButtonsUI getButtonsUI() {
		return (ButtonsUI) jButtons;
	}
	public void setEditorsUI(int index){
		jEditors.setSelectedIndex(index);
	}
}
